package cn.picclife.mwx.manager.sys.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;

import cn.picclife.mwx.manager.sys.model.bo.ArchiveBo;
import cn.picclife.mwx.manager.sys.model.bo.DataResponse;
import cn.picclife.mwx.manager.sys.model.bo.PageCount;
import cn.picclife.mwx.manager.sys.model.bo.PageResponse;
import cn.picclife.mwx.manager.sys.model.bo.UpdateCollectReq;
import cn.picclife.mwx.manager.sys.service.IArchiveService;
import cn.picclife.mwx.manager.util.LogUtil;
import cn.picclife.mwx.manager.util.enums.ResponseStatusEnum;

/**
 * 归档管理
 * @author Administrator
 *
 */
@RestController
public class ArchiveController {
	
	@Autowired
	private IArchiveService sevice;
	
	private Log log = LogFactory.getLog(QualityDataController.class);
	@ResponseBody
	@RequestMapping(value = "/archive/addArchive")
	public DataResponse addArchive(HttpServletRequest request, HttpServletResponse response, @RequestBody ArchiveBo bo){
		
		DataResponse dataResponse = new DataResponse();
		LogUtil.info("请求入参：" + JSONObject.toJSONString(bo));
		try {
			dataResponse = sevice.insertArchive(bo);
		} catch (Exception e) {
			LogUtil.error(ResponseStatusEnum.EXCEPTION.getName(), e);
			dataResponse.setCode(ResponseStatusEnum.EXCEPTION.getCode());
			dataResponse.setMsg(ResponseStatusEnum.EXCEPTION.getName() + "；" + e.getMessage());
		}
		return dataResponse;
	}
	
	@ResponseBody
	@RequestMapping(value = "/archive/queryAllArchive")
	public DataResponse queryAllArchive(HttpServletRequest request, HttpServletResponse response){
		
		DataResponse dataResponse = new DataResponse();
		try {
			dataResponse = sevice.getAllArchive();
		} catch (Exception e) {
			log.error(e);
			dataResponse.setCode(ResponseStatusEnum.EXCEPTION.getCode());
			dataResponse.setMsg(ResponseStatusEnum.EXCEPTION.getName() + "；" + e.getMessage());
		}
		return dataResponse;
	}
	/**
	 * 归档历史查询
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/archive/queryArchiveList", method= {RequestMethod.POST})
	public PageResponse queryDataList(@RequestBody UpdateCollectReq req) {
		
		log.info("===========queryArchiveList归档历史查询接口请求报文："+JSONObject.toJSON(req).toString());
		PageResponse pageResponse = new PageResponse();
		PageCount pageCount = new PageCount();
		try {
			pageCount = sevice.queryDataList(req);
		} catch (Exception e) {
			log.error(e);
			pageResponse.setCode(ResponseStatusEnum.EXCEPTION.getCode());
			pageResponse.setMsg(ResponseStatusEnum.EXCEPTION.getName());
			log.info("===========queryArchiveList归档历史查询查询接口返回报文："+JSONObject.toJSON(pageResponse).toString());
			return pageResponse;
		}
		pageResponse.setCode(ResponseStatusEnum.SUCCESS_CODE.getCode());
		pageResponse.setMsg(ResponseStatusEnum.SUCCESS_CODE.getName());
		pageResponse.setPageCount(pageCount);
		log.info("===========queryArchiveList归档历史查询接口返回成功=========");
		return pageResponse;
	}
	

}
